package com.example.seckill.error;

import com.example.seckill.json.CommonErrorEnumSerializer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonKey;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

//@JsonSerialize(using = CommonErrorEnumSerializer.class)
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum CommonErrorEnum implements CommonError{
    //通用异常
    PARAMETER_VALIDATION_ERROR(10001,"参数不合法"),
    UNKNOWN_ERROR(10002,"未知错误"),
    DUPLICATEKEY_ERROR(10003,"字段重复"),
    NOT_FOUND_404(10404,"url路径错误"),
    //2开头是用户异常
    USER_NOT_EXIST(20001,"用户不存在"),
    USER_NOT_LOGIN(20002,"用户没登陆"),
    //3开头是商品异常
    STOCK_NOT_ENOUGH(30001,"商品库存不足"),

    //4开头是订单错误
    PROMO_ID_ERROR(40001, "促销信息不存在"),
    ;
    Integer errCode;
    String errMsg;

    CommonErrorEnum(Integer errCode, String errMsg) {
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    @Override
    public Integer getErrCode() {
        return errCode;
    }

    @Override
    public String getErrMsg() {
        return errMsg;
    }

    @Override
    public CommonErrorEnum setErrMsg(String errMsg) {
        this.errMsg=errMsg;
        return this;
    }
}
